/*
 * @Author: HanYaJun
 * @Date: 2023-01-29 09:34:44
 * @Email: hanyajun@wedobest.com.cn
 * @Description: 星消灭重玩
 */

import dwfUIConfig from '../../../dwf/scripts/Global/dwfUIConfig';
import { guiForm } from '../../../Public/game/guiManager/UIFrame/BaseForm';
import { ModalOpacity } from '../../../Public/game/guiManager/UIFrame/SysDefine';
import { ModalType } from '../../../Public/game/guiManager/UIFrame/UIArgsType';
import { GTR } from '../../../Public/GTR';
import xxmUIConfig from '../Global/xxmUIConfig';
import xxmGameEvents from '../Global/xxmGameEvents';

let trace = function (...args) {
    GTR.logg.log("xxmReplay【HYJ】", ...args);
}
let traceError = function (...args) {
    GTR.logg.error("xxmReplay【HYJ】", ...args);
}

const { ccclass, property } = cc._decorator;
@ccclass
export class xxmReplay extends cc.Component {
    // 阴影类型
    modalType = new ModalType(ModalOpacity.OpacityHigh, false);

    /**
     * @description: 则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑
     */
    protected start() {
        let buttons: cc.Button[] = this.node.getComponentsInChildren(cc.Button);
        buttons.forEach((button) => {
            button.node.on('click', this.btnClickCallBack, this);
        });
    }

    /**
     * @description: 关闭弹窗动效
     */
    public async showEffect() {

    }

    /**
     * @description: 点击事件
     * @param {cc} button
     */
    private btnClickCallBack(button: cc.Button) {
        if (button.node.name === "replay") {
            // 关闭该界面
            GTR.ui.close(xxmUIConfig.ReplayUI);
            // 重置关卡
            GTR.event.dispatchEvent(xxmGameEvents.REPLAY);
            // 游戏结束播放下一关动画, 加载关卡目标分数页
            GTR.ui.open(xxmUIConfig.LevelScoreUI);
        } else if (button.node.name === "btnReturn") {
            GTR.ui.close(xxmUIConfig.PlayUI);
            GTR.ui.open(dwfUIConfig.PlayUI);
        }
    }

    /**
     * @description: 当该组件被销毁时调用
     */
    public onDestroy(): void {
    }
}

